#!/usr/bin/rnv python
#:coding:utf-8
import pymysql, sys,time,datetime
date = float(time.time())-86400
ltime=time.localtime(date)
timeStr = time.strftime("%Y%m%d", ltime)
datestrftime=time.strftime('%Y-%m-%d',ltime)

# sql=sys.argv[1]

def select_mysql(sql):
    conn = pymysql.connect(host='10.0.0.83', user='sso_r', passwd='8EhZQS5i6jEc4iapjkvJ', db='sso',
                           charset='UTF8')

    cur = conn.cursor()
    reCount = cur.execute(sql)

    nRet = cur.fetchall()
    cur.close()

    conn.close()
    return nRet


def insert_mysql(sql):
    conn = pymysql.connect(host='121.201.68.21', port=3307, user='jiang', passwd='jiangwenhui', db='daxiangzhanshi',

                           charset='UTF8')

    cur = conn.cursor()

    cur.execute(sql)
    nRet = cur.fetchall()
    conn.commit()

    cur.close()

    conn.close()
    return nRet

if __name__ == "__main__":

    #select = "SELECT COUNT(1) FROM hm_member_user mur WHERE mur.create_time >= unix_timestamp(curdate());"
    select = "SELECT round(COUNT(1)*1,0) as 用户注册数量 FROM hm_member_user mur WHERE mur.create_time >= unix_timestamp(curdate());"
    data = select_mysql(select)


    #print(data)
    insert = "insert into app01_user_num values (null,'%s',curdate())"%(data[0][0])
    insert_mysql(insert)
    print(insert)
